"""
Problem 52: https://projecteuler.net/problem=52

Permuted multiples

It can be seen that the number, 125874, and its double, 251748, contain exactly
the same digits, but in a different order.

Find the smallest positive integer, x, such that 2x, 3x, 4x, 5x, and 6x,
contain the same digits.
"""

# _*_ conding:UTF-8 _*_
'''
@author = Kuperain
@email = kuperain@aliyun.com
@IDE = VSCODE Python3.8.3
@creat_time = 2022/5/17
'''




from collections import Counter
def solution() -> int:
    '''
    x1,x2,x3,x4,x5,x6, where xi = i*x1

    #1 xi have same length, so the first 2 digit of x1 
       must be less '17','18','19',...
    #2 x3 = 0 mod 3, and x1,x3 have same digits, so x1 % 3 == 0
    #3 if x1 is even, the end digit of x5 is 0, so 0 in x1
       if x1 is odd, the end digit of x5 is 5, so 5 in x1
    #4 if the end of x1 is 1, the end of x2 is 2, so 2 in x1


    '''
    x1 = 102
    while True:
        xs = str(x1)
        if int(xs[:2]) >= 17:
            x1 += 3
            continue

        isodd = x1%2
        if not isodd and '0' not in xs:
            x1+=3
            continue        
        if isodd and '5' not in xs:
            x1+=3
            continue

        if x1%10==1 and '2' not in xs:
            x1 += 3
            continue

        # print('x1',x1)

        Counter1 = Counter(str(x1))
        Counter2 = Counter(str(x1*2))
        if Counter2 != Counter1:
            x1 += 3
            continue
        Counter3 = Counter(str(x1*3))
        if Counter3 != Counter1:
            x1 += 3
            continue
        Counter4 = Counter(str(x1*4))
        if Counter4 != Counter1:
            x1 += 3
            continue
        Counter5 = Counter(str(x1*5))
        if Counter5 != Counter1:
            x1 += 3
            continue
        Counter6 = Counter(str(x1*6))
        if Counter6 != Counter1:
            x1 += 3
            continue

        return [x1*k for k in range(1,7)]


if __name__ == "__main__":
    import doctest
    doctest.testmod(verbose=False)

    print(solution())
    # [142857, 285714, 428571, 571428, 714285, 857142]
